import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '帝可得', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    name: 'Example',
    meta: { title: '工单管理', icon: 'el-icon-s-order' },
    children: [
      {
        path: 'yunyin',
        name: 'yunyin',
        component: () => import('@/views/work-order-management/yunyin/index.vue'),
        meta: { title: '运营工单' }
      },
      {
        path: 'yunwei',
        name: 'Tree',
        component: () => import('@/views/work-order-management/yunwei/index.vue'),
        meta: { title: '运维工单' }
      }
    ]
  },
  {
    path: '/point',
    component: Layout,
    meta: { title: '点位管理', icon: 'el-icon-map-location' },
    children: [
      {
        path: 'quyu',
        name: 'quyu',
        component: () => import('@/views/point/quyu/index.vue'),
        meta: { title: '区域管理' }
      },
      {
        path: 'dianwei',
        name: 'dianwei',
        component: () => import('@/views/point/dianwei/index.vue'),
        meta: { title: '点位管理' }
      },
      {
        path: 'hezuo',
        name: 'hezuo',
        component: () => import('@/views/point/hezuo/index.vue'),
        meta: { title: '合作商管理' }
      }
    ]
  },
  {
    path: '/equipment',
    component: Layout,
    meta: { title: '设备管理', icon: 'el-icon-data-line' },
    children: [
      {
        path: 'guanli',
        name: 'guanli',
        component: () => import('@/views/equipment/guanli/index.vue'),
        meta: { title: '设备管理' }
      },
      {
        path: 'zhuangtai',
        name: 'zhuangtai',
        component: () => import('@/views/equipment/zhuangtai/index.vue'),
        meta: { title: '设备状态' }
      },
      {
        path: 'leixing',
        name: 'leixing',
        component: () => import('@/views/equipment/leixing/index.vue'),
        meta: { title: '设备类型管理' }
      }
    ]
  },
  {
    path: '/users',
    component: Layout,
    meta: { title: '人员管理', icon: 'el-icon-user' },
    children: [
      {
        path: 'liebiao',
        name: 'liebiao',
        component: () => import('@/views/users/liebiao/index.vue'),
        meta: { title: '人员列表' }
      },
      {
        path: 'tongji',
        name: 'tongji',
        component: () => import('@/views/users/tongji'),
        meta: { title: '人效统计' }
      },
      {
        path: 'gongzuoliang',
        name: 'gongzuoliang',
        component: () => import('@/views/users/gongzuoliang/index.vue'),
        meta: { title: '工作量列表' }
      }
    ]
  },
  {
    path: '/goods',
    component: Layout,
    meta: { title: '商品管理', icon: 'el-icon-box' },
    children: [
      {
        path: 'goodsType',
        name: 'goodsType',
        component: () => import('@/views/goods/leixing'),
        meta: { title: '商品类型' }
      },
      {
        path: 'manage',
        name: 'manage',
        component: () => import('@/views/goods/guanli'),
        meta: { title: '商品管理' }
      }
    ]
  },
  {
    path: '/tactics',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/tactics/index.vue'),
      meta: { title: '策略管理', icon: 'el-icon-magic-stick' }
    }]
  },
  {
    path: '/order',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/order/index.vue'),
      meta: { title: '订单管理', icon: 'el-icon-tickets' }
    }]
  },
  {
    path: '/report',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/report/index'),
      meta: { title: '对账统计', icon: 'el-icon-s-help' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
